package com.tensai.study.java.supper.branch;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@Slf4j
public class DDD {


    private static final String MAN = "man";
    private static final String WOMAN = "woman";
    @Data
    static class Person{
        private String gender;
        private String name;

        private static final Map<String, Consumer<String>> FUNC_MAP = new ConcurrentHashMap<>();
        static {
            FUNC_MAP.put(MAN,person -> log.info(person + "应该去男厕所"));
            FUNC_MAP.put(WOMAN,person -> log.info(person + "应该去女厕所"));
        }
        public void goToWC(){
            FUNC_MAP.get(gender).accept(name);
        }
    }

    static class PersonFactory{
        public static Person initPerson(String name ,String gender){
            Person p = new Person();
            p.setName(name);
            p.setGender(gender);
            return p;
        }

        private PersonFactory() {

        }
    }
    public static void main(String[] args) {
        Person p = PersonFactory.initPerson("张三",MAN);
        Person p2 = PersonFactory.initPerson("张三他老婆",WOMAN);
        p.goToWC();
        p2.goToWC();
    }
}
